<?php
switch($action){
	/************************************** group BEGIN ************************************************/
	case "groups":
	$rows=$db->row_select("groups","groupid<100 and groupname<>''",0,"*","id");
	$rows2=$db->row_select("groups","groupid>100",0,"*","groupid");
echo <<<EOT
<script>
var hasDelTip=false;
var maxIndex=0;
function addGroup(groupid, groupname, marklower, markhigher, starnum, color){
	var minitems=document.getElementsByName("groups_marklower[]");
	if(minitems.length>=80){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
		popwin.showDialog(4,"禁止操作","最多允许使用80个普通组。",btns,280,130);
		return;
	}
	var s="<table class=\"table_1\" width=\"100%\"><tr><td class=\"td_6\"><div class=\"td_6_1\"><input type=\"text\" size=\"15\" value=\""+groupname+"\" name=\"groups_groupname[]\" class=\"text_css\" /></div><div class=\"td_6_2\"><input type='text' value='"+marklower+"' size='5' name='groups_marklower[]' class='input_readonly' readonly='true' /> ~ <input type='text' value='"+markhigher+"' size='5'  name='groups_markhigher[]' class=\"text_css\" /></div><div class=\"td_6_3\"><input type='text' value='"+starnum+"' size='3'  name='groups_starnum[]' class=\"text_css\" /></div><div class=\"td_6_4\"><input type='text' value='"+color+"' size='10' style='color:"+color+"'  name='groups_color[]' onfocus='curInput=this; colorpicker.choose(event)' class=\"text_css\" /></div><div class=\"td_6_5\"><a href=\"javascript:delGroupTips("+maxIndex+")\">删除</a>"+ (groupid==''?"":"| <a href=\"admin.php?inc=user&action=popedom&groupid="+groupid+"\">权限</a>")+"</div></td></tr></table>";
	var ele=document.createElement('div');
	ele.id="group_div_"+maxIndex;
	ele.innerHTML=s;
	E("groupsdiv").appendChild(ele);
	maxIndex++;
}
function delGroupTips(index){
	if(!hasDelTip){
		var btns=[{value:" 确 定 ",onclick:"mainifm.delGroup("+index+");popwin.close();",focus:true}];
		popwin.showDialog(2,"操作提示","要保存删除结果，请在编辑完成之后点击“提交”按钮",btns,280,130);
		hasDelTip=true;
	}else{
		delGroup(index);
	}
}
function delGroup(index){
	E("group_div_"+index+"").innerHTML ="";
	setMinMaxInput();
	setInputEvent();
}
</script>

	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div class="div_clear" style="height:10px;"></div>
	<div id="t1">
		<form id="groupsform" onsubmit="return false;">
		<div class="tips_1"><b>提示</b><br />
	* 用户组分为普通组和系统组，普通组是由论坛系统的积分控制的。最多使用80个普通组。<br /></div>
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1" width="100%">
			<tr style="font-weight:bold;color:#333333;"><td class="td_6"><div class="td_6_1">名称</div><div class="td_6_2">积分</div><div class="td_6_3">星星数</div><div class="td_6_4">头衔颜色</div><div class="td_6_5">操作</div></td></tr>
		</table>
		<div id="groupsdiv">
EOT;
			for($i=0;$i<count($rows);$i++){
				$row=$rows[$i];
				echo("<script>addGroup(\"{$row['groupid']}\",\"{$row['groupname']}\",\"{$row['marklower']}\",\"{$row['markhigher']}\",\"{$row['starnum']}\",\"{$row['color']}\");</script>");			
			}
			
echo <<<EOT
		</div>
			<table class="table_1" width="100%">
			<tr><td class="td_6"><a class="td_5_1a" href="javascript:addNew()"><img src="images/ico_add.gif" border="0" /> 添加用户组</a></td></tr>
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_groups()" /></td></tr>
		</table>
		</form>
	</div>
	<div id="t2">
		<form id="groupsform2" onsubmit="return false;">
		<div class="tips_1"><b>提示</b><br />
	* 用户组分为普通组和系统组，系统组是由人为设定的，不会由论坛系统自行改变。系统组不能增删，只能修改其名称。<br /></div>
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1" width="100%">
			<tr style="font-weight:bold;color:#333333;"><td class="td_6"><div class="td_6_1">名称</div><div class="td_6_2">说明</div><div class="td_6_3">星星数</div><div class="td_6_4">头衔颜色</div><div class="td_6_5">操作</div></td></tr>
	
EOT;
			for($i=0;$i<count($rows2);$i++){
				$row=$rows2[$i];
				echo("<tr><td class=\"td_6\"><div class=\"td_6_1\"><input type=\"hidden\" size=\"3\" value=\"{$row['id']}\" name=\"groups[{$i}][id]\"  /><input type=\"text\" size=\"15\" value=\"{$row[groupname]}\" name=\"groups[{$i}][groupname]\"   class=\"text_css\" /></div><div class=\"td_6_2\" style='color:#666666;font-weight:bold;'>{$row[groupdesc]}</div><div class=\"td_6_3\"><input type='text' value='{$row[starnum]}' size='3'  name='groups[{$i}][starnum]' class=\"text_css\" /></div><div class=\"td_6_4\"><input type='text' value='{$row[color]}' size='10' style='color:{$row[color]}' onfocus='curInput=this; colorpicker.choose(event)'  name='groups[{$i}][color]' class=\"text_css\" /></div><div class=\"td_6_5\"><a href=\"admin.php?inc=user&action=popedom&groupid={$row['groupid']}\">权限</a></div></td></tr>");				
			}
			
echo <<<EOT
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_groups2()" /></td></tr>
		</table>
		</form>
		
	</div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
<script>
var curInput;
var hasErr=false;
var smallNowTab;
var pt = new Tabs();
pt.classpre="smalltab_";
pt.container = "smalltab_container";
pt.createTab("t1","普通组","",true,"n");
pt.createTab("t2","系统组","",false,"n");
pt.init = function(){
	smallNowTab = pt.nowTab;
};
pt.onclick = function(){
	smallNowTab = pt.nowTab;
};		
pt.initTab();
pt.clickNowTab();

var isoff="{$row['isoff']}";
setRadioCheck("isoff",isoff);

function ajax_groups(){
	checkMark();
	if(hasErr){return;}
	popwin.loading();
	ajaxPost("groupsform","user_ajax.php?action=savegroups",ajax_groups_callback);
}
function ajax_groups_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"修改成功","普通用户组修改成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function ajax_groups2(){
	popwin.loading();
	ajaxPost("groupsform2","user_ajax.php?action=savegroups2",ajax_groups2_callback);
}
function ajax_groups2_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"修改成功","系统用户组修改成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function setMinMaxInput(){
	var minitems=document.getElementsByName("groups_marklower[]");
	minitems[0].value="-999999999";
	var maxitems=document.getElementsByName("groups_markhigher[]");
	maxitems[maxitems.length-1].value="999999999";
	maxitems[maxitems.length-1].readOnly="true";
	maxitems[maxitems.length-1].className="input_readonly";

}

function setInputEvent(){
	var maxitems=document.getElementsByName("groups_markhigher[]");
	for(var i=0; i<maxitems.length; i++){
		maxitems[i].onkeyup=function(){
			checkMark();
		}
	}
}

function checkMark(){
	hasErr=false;
	var maxitemstt=document.getElementsByName("groups_markhigher[]");
	for(var i=0; i<maxitemstt.length-1; i++){
		var t=function(n){
			var minitems=document.getElementsByName("groups_marklower[]");
			var maxitems=document.getElementsByName("groups_markhigher[]");
			minitems[n+1].value=maxitems[n].value*1+1;
			if(n==0||n==maxIndex){
				maxitems[n].className="";
			}else{
				if( maxitems[n].value*1 > minitems[n].value*1 ){
					maxitems[n].className="";
				}else{
					maxitems[n].className="input_errstyle";
					hasErr=true;
				}
			}
		}(i);
	}
}

function addNew(){
	addGroup('','','','','','');
	var maxitems=document.getElementsByName("groups_markhigher[]");
	maxitems[maxitems.length-2].readOnly=false;
	maxitems[maxitems.length-2].className="";
	maxitems[maxitems.length-2].value="0";
	setMinMaxInput();
	setInputEvent();
}

setMinMaxInput();
setInputEvent();

colorpicker.previewColor = function(color){
	color=color==""?"#000000":color;
	if(curInput){
		curInput.style.color = color;
		curInput.value = color;
	}
}
colorpicker.chooseColor = function(color){
	color=color==""?"#000000":color;
	if(curInput){
		curInput.style.color = color;
		curInput.value = color;
	}
}

</script>

EOT;
	break;
	/************************************** group END ************************************************/

	/************************************** popedom BEGIN ************************************************/
	case "popedom":
	$groupid=numFilter($_GET['groupid']);
	$row=$db->row_select_one("groups","groupid={$groupid}","*");
	$popedom=$row['popedom'];
	$ps=explode("|",$popedom);
echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div id="t1">
		<form id="popedomform" onsubmit="return false;">
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1">
			<tr><td class="td_0">允许访问论坛:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[0]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[0]" class="radio_css" /> 否</td><td class="td_2">是否允许访问论坛</td></tr>
			<tr><td class="td_0">阅读权限:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[1]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[1]" class="radio_css" /> 否</td><td class="td_2">是否允许阅读帖子</td></tr>
			<tr><td class="td_0">允许查看用户资料:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[2]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[2]" class="radio_css" /> 否</td><td class="td_2">是否允许查看其他用户的资料</td></tr>
			<tr><td class="td_0">允许发送短信:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[3]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[3]" class="radio_css" /> 否</td><td class="td_2">是否允许使用站内短信给其他用户</td></tr>
			<tr><td class="td_0">允许使用搜索:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="0" name="popedom[4]" class="radio_css" /> 禁用 <br /><input type="radio" value="1" name="popedom[4]" class="radio_css" /> 允许搜索标题/作者 <br /><input type="radio" value="2" name="popedom[4]" class="radio_css" /> 允许全文搜索</td><td class="td_2">论坛搜索的权限</td></tr>
			<tr><td class="td_0">允许自定义头衔:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[5]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[5]" class="radio_css" /> 否</td><td class="td_2">是否允许用户自定义头衔</td></tr>
			<tr><td class="td_0">允许发起投票:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[6]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[6]" class="radio_css" /> 否</td><td class="td_2">是否允许用户发起投票</td></tr>
			<tr><td class="td_0">允许发起悬赏:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[7]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[7]" class="radio_css" /> 否</td><td class="td_2">是否允许发起悬赏</td></tr>

			<tr style='display:none;'><td class="td_0">允许发布商品:</td><td class=""></td></tr>
			<tr style='display:none;'><td class="td_1"><input type="radio" value="1" name="popedom[8]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[8]" class="radio_css" /> 否</td><td class="td_2">是否允许用户发布商品</td></tr>
			
			<tr><td class="td_0">允许发新帖:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[9]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[9]" class="radio_css" /> 否</td><td class="td_2">是否允许用户发布新话题</td></tr>
			<tr><td class="td_0">允许发表回复:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[10]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[10]" class="radio_css" /> 否</td><td class="td_2">是否允许用户发布回复</td></tr>
			<tr><td class="td_0">允许直接发帖:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="0" name="popedom[11]" class="radio_css" /> 根据系统设置 <br /><input type="radio" value="1" name="popedom[11]" class="radio_css" /> 需要审核 <br /><input type="radio" value="2" name="popedom[11]" class="radio_css" /> 不需要审核</td><td class="td_2">用户发布帖子是否经过审核</td></tr>
			
			<tr style='display:none;'><td class="td_0">允许出售帖子:</td><td class=""></td></tr>
			<tr style='display:none;'><td class="td_1"><input type="radio" value="1" name="popedom[12]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[12]" class="radio_css" /> 否</td><td class="td_2">是否运行用户出售帖子</td></tr>
			
			<tr><td class="td_0">允许下载/查看附件:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[13]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[13]" class="radio_css" /> 否</td><td class="td_2">是否运行用户下载/查看附件</td></tr>
			<tr><td class="td_0">允许上传附件:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="1" name="popedom[14]" class="radio_css" /> 是 &nbsp; &nbsp;<input type="radio" value="0" name="popedom[14]" class="radio_css" /> 否</td><td class="td_2">是否运行用户上传附件</td></tr>
			<tr><td class="td_0">最大附件尺寸:(KB)</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$ps[15]}" size="8" name="popedom[15]" class="text_css" /></td><td class="td_2">上传附件的最大尺寸，单位:KB</td></tr>
			<tr><td class="td_0">每天最多附件数量:(个)</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$ps[16]}" size="8" name="popedom[16]" class="text_css" /></td><td class="td_2">每天最多上传的附件数量</td></tr>
			<tr><td class="td_0">允许附件类型:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$ps[17]}" size="30" name="popedom[17]" class="text_css" /></td><td class="td_2">允许上传的附件类型，用" , "隔开</td></tr>
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_savepopedom()" /></td><td class=""></td></tr>
		</table>
		</form>
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
	<script>
	var smallNowTab;
	var pt = new Tabs();
	pt.classpre="smalltab_";
	pt.container = "smalltab_container";
	pt.createTab("t1","用户组: {$row['groupname']}","",true,"n");
	pt.init = function(){
		smallNowTab = pt.nowTab;
	};
	pt.onclick = function(){
		smallNowTab = pt.nowTab;
	};		
	pt.initTab();
	pt.clickNowTab();
	
	try{
		setRadioCheck("popedom[0]","{$ps[0]}");
		setRadioCheck("popedom[1]","{$ps[1]}");
		setRadioCheck("popedom[2]","{$ps[2]}");
		setRadioCheck("popedom[3]","{$ps[3]}");
		setRadioCheck("popedom[4]","{$ps[4]}");
		setRadioCheck("popedom[5]","{$ps[5]}");
		setRadioCheck("popedom[6]","{$ps[6]}");
		setRadioCheck("popedom[7]","{$ps[7]}");
		setRadioCheck("popedom[8]","{$ps[8]}");
		setRadioCheck("popedom[9]","{$ps[9]}");
		setRadioCheck("popedom[10]","{$ps[10]}");
		setRadioCheck("popedom[11]","{$ps[11]}");
		setRadioCheck("popedom[12]","{$ps[12]}");
		setRadioCheck("popedom[13]","{$ps[13]}");
		setRadioCheck("popedom[14]","{$ps[14]}");
	}catch(err){
	
	}
	
	
	function ajax_savepopedom(){
		popwin.loading();
		ajaxPost("popedomform","user_ajax.php?action=savepopedom&groupid={$groupid}",ajax_savepopedom_callback);
	}
	function ajax_savepopedom_callback(data){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
		popwin.loaded();
		if(data=="y"){
			popwin.showDialog(1,"修改成功","用户组 ({$row['groupname']})编辑修改成功",btns,280,130);
		}else{
			popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
		}
	}
	
	</script>
EOT;
	break;
	/************************************** popedom END ************************************************/


	/************************************** verify BEGIN ************************************************/
	case "verify":
	$dwidth=array(0,120,160,170,230,230);
	$rows=$db->row_select("users","groupid=".GROUP_NOVERIFY,0,"*","id");
echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div class="div_clear" style="height:10px;"></div>
	<div id="t1">
		<form id="verifyform" onsubmit="return false;">
		<div class="tips_1"><b>提示</b><br />
	* 本功能仅在 “全局 » 论坛注册设置 » 注册限制 » 注册审核”开启时才有效。</div>
		<div class="div_clear" style="height:10px;"></div>
		
EOT;
		echo("<table class=\"table_1\" width=\"100%\">");
		echo("<tr style=\"font-weight:bold;color:#333333;\"><td class=\"row_0\"><div class=\"rowdiv_0\" style=\"width:{$dwidth[1]}px;\">操作</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[2]}px;\">用户名/邮箱</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[3]}px;\">注册IP/时间</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[4]}px;\">注册原因</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[5]}px;\">审核留言</div></td></tr>");
		for($i=0;$i<count($rows);$i++){
			$row=$rows[$i];
			$row['username']=htmlFilter($row['username']);
			echo("<tr><td class=\"row_0\" style=\"line-height:180%;\"><div class='rowdiv_0' style='width:{$dwidth[1]}px;'><input type='radio' value='0' name='doaction[{$row['id']}]' class='radio_css' /> 忽略 &nbsp; <input type='radio' value='1' name='doaction[{$row['id']}]' checked='true' class='radio_css' /> 通过<br /><input type='radio' value='2' name='doaction[{$row['id']}]' class='radio_css' /> 否决 &nbsp; <input type='radio' value='3' name='doaction[{$row['id']}]' class='radio_css' /> 删除<br /></div><div class='rowdiv_0' style='width:{$dwidth[2]}px;'><span style='color:#FF6600;'>{$row['username']}</span><br />{$row['email']}</div><div class='rowdiv_0' style='width:{$dwidth[3]}px;'>{$row['signupip']}<br />{$row['signuptime']}</div><div class='rowdiv_0' style='width:{$dwidth[4]}px;'><textarea style='width:200px;height:50px;color:#999999' readonly='true'>{$row['signupreason']}</textarea></div><div class='rowdiv_0' style='width:{$dwidth[5]}px;'><textarea style='width:200px;height:50px;' name='verifydesc[{$row['id']}]'></textarea></div></td></tr>");				
		}
		echo("<tr><td class=\"td_3\"><input class=\"button_css\" type=\"button\" value=\"  提  交  \" onclick=\"ajax_verify()\" /></td></tr>");
		echo("</table>");
		
echo <<<EOT
		
	
	</form>
</div>
<div id="t2"></div>
<div id="t3"></div>
<div class="div_clear" style="height:30px;"></div>
<script>
var smallNowTab;
var pt = new Tabs();
pt.classpre="smalltab_";
pt.container = "smalltab_container";
pt.createTab("t1","用户审核","",true,"n");
pt.init = function(){
	smallNowTab = pt.nowTab;
};
pt.onclick = function(){
	smallNowTab = pt.nowTab;
};		
pt.initTab();
pt.clickNowTab();
function ajax_verify(){
	popwin.loading();
	ajaxPost("verifyform","user_ajax.php?action=verify",ajax_verify_callback);
}
function ajax_verify_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"审核成功","审核成功",btns,280,130);
	}else{
		popwin.showDialog(0,"审核失败","操作失败:<br />"+data,btns,280,130);
	}
}
</script>

EOT;
	break;
	/************************************** verify END ************************************************/


	/************************************** edituser BEGIN ************************************************/
	case "edituser":
	$uid=numFilter($_GET['uid']);
	$row=$db->row_select_one("users","id={$uid}","*");
	$row['signuptime']=getDateStr($row['signuptime'],false,false);
	$row['logintime']=getDateStr($row['logintime'],false,false);
	$row['lastlogintime']=getDateStr($row['lastlogintime'],false,false);
	$row['displayname']=htmlFilter($row['username']);
	$creditsstr='';
	foreach($cache_credits as $credits){
		$code=$credits['creditscode'];
		$creditsstr.="<tr><td class=\"td_0\">{$credits['creditsname']}:</td><td class=\"\"></td></tr><tr><td class=\"td_1\"><input type='text' value='{$row[$code]}' name='user[$code]' class=\"text_css\" /></td><td class=\"td_2\"></td></tr>";
	}
echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div id="t1">
		<form id="userform" onsubmit="return false;">
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1">
			<tr><td class="td_0">用户名:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="hidden" value="{$row['username']}" size="30" name="user[username]" /><b>{$row['displayname']}</b></td><td class="td_2"></td></tr>
			<tr><td class="td_0">新密码:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="" size="30" name="user[userpass]" class="text_css" /></td><td class="td_2">如果不更改密码此处请留空</td></tr>
			<tr><td class="td_0">头像:</td><td class=""></td></tr>
			<tr><td class="td_1"><img src="../userpic.php?uid={$uid}&type=big&random=1" border="0" class="userpic" /><img src="../userpic.php?uid={$uid}&type=small&random=1" border="0" class="userpic" /><br /><input type="checkbox" value="1" name="deluserpic[]" class="checkbox_css" /> 删除头像</td><td class="td_2"></td></tr>
			<tr><td class="td_0">性别:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="radio" value="0" name="row[sex]" class="radio_css" /> 男 &nbsp; &nbsp;<input type="radio" value="1" name="row[sex]" class="radio_css" /> 女</td><td class="td_2"></td></tr>
			<tr><td class="td_0">Email:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['email']}" size="30" name="user[email]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">注册IP:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['signupip']}" size="30" name="user[signupip]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">注册时间:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['signuptime']}" size="30" name="user[signuptime]" class="text_css" /></td><td class="td_2">请保持格式: 2000-01-01 00:00</td></tr>
			<tr><td class="td_0">上次登录时间:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['logintime']}" size="30" name="user[logintime]" class="text_css" /></td><td class="td_2">请保持格式: 2000-01-01 00:00</td></tr>
			<tr><td class="td_0">真实姓名:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['realname']}" size="30" name="user[realname]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">生日:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['birthday']}" size="30" name="user[birthday]" class="text_css" /></td><td class="td_2">请保持格式: 2000-01-01</td></tr>
			<tr><td class="td_0">QQ:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['qq']}" size="30" name="user[qq]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">MSN:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['msn']}" size="30" name="user[msn]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">联系电话:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['phone']}" size="30" name="user[phone]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">签名:</td><td class=""></td></tr>
			<tr><td class="td_1"><textarea style='width:200px;height:80px;' name="user[signature]">{$row['signature']}</textarea></td><td class="td_2"></td></tr>
			<tr><td class="td_0">发帖数:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['postsnum']}" size="30" name="user[postsnum]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">用户自定义头衔:</td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="{$row['usertitle']}" size="30" name="user[usertitle]" class="text_css" /></td><td class="td_2"></td></tr>
			{$creditsstr}
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_edituser()" /></td><td class=""></td></tr>
		</table>
		</form>
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
	<script>
	var smallNowTab;
	var pt = new Tabs();
	pt.classpre="smalltab_";
	pt.container = "smalltab_container";
	pt.createTab("t1","编辑用户","",true,"n");
	pt.init = function(){
		smallNowTab = pt.nowTab;
	};
	pt.onclick = function(){
		smallNowTab = pt.nowTab;
	};		
	pt.initTab();
	pt.clickNowTab();
	
	setRadioCheck("row[sex]",{$row['sex']});
	
	function ajax_edituser(){
		popwin.loading();
		ajaxPost("userform","user_ajax.php?action=edituser&uid={$uid}",ajax_edituser_callback);
	}
	function ajax_edituser_callback(data){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
		popwin.loaded();
		if(data=="y"){
			popwin.showDialog(1,"修改成功","用户 ({$row['displayname']})编辑成功",btns,280,130);
		}else{
			popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
		}
	}
	
	</script>
EOT;
	break;
	/************************************** edituser END ************************************************/

	/************************************** editusergroup BEGIN ************************************************/
	case "editusergroup":
	$uid=numFilter($_GET['uid']);
	$row=$db->row_select_one("users","id={$uid}","*");
	$row['displayname']=htmlFilter($row['username']);
	if($row['groupid']<100){
		$gstr="<optgroup label=\"普通组\"><option value=\"{$row['groupid']}\">{$cache_groups[$row['groupid']]['groupname']}</option></optgroup>";
	}else{
		$gstr="<optgroup label=\"普通组\"><option value=\"-1\">由用户的积分决定</option></optgroup>";		
	}
echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div id="t1">
		<form id="userform" onsubmit="return false;">
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1">
			<tr><td class="td_0">用户名:</td><td class=""></td></tr>
			<tr><td class="td_1"><b>{$row['displayname']}</b></td><td class="td_2"></td></tr>
			<tr><td class="td_0">用户组:</td><td class=""></td></tr>
			<tr><td class="td_1"><select size="10" style='width:200px;padding-left:5px;' name="groupid" id="groupid">{$gstr}<optgroup label="系统组">{$cache_groups2option}</optgroup></select></td><td class="td_2">请选择所属用户组</td></tr>
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_editusergroup()" /></td><td class=""></td></tr>
		</table>
		</form>
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
	<script>
	var smallNowTab;
	var pt = new Tabs();
	pt.classpre="smalltab_";
	pt.container = "smalltab_container";
	pt.createTab("t1","编辑所属用户组","",true,"n");
	pt.init = function(){
		smallNowTab = pt.nowTab;
	};
	pt.onclick = function(){
		smallNowTab = pt.nowTab;
	};		
	pt.initTab();
	pt.clickNowTab();
	
	setSelect("groupid","{$row['groupid']}");
	
	function ajax_editusergroup(){
		popwin.loading();
		ajaxPost("userform","user_ajax.php?action=editusergroup&uid={$uid}",ajax_editusergroup_callback);
	}
	function ajax_editusergroup_callback(data){
		var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
		popwin.loaded();
		if(data=="y"){
			popwin.showDialog(1,"修改成功","用户 ({$row['displayname']})编辑成功",btns,280,130);
		}else{
			popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
		}
	}
	
	</script>
EOT;
	break;
	/************************************** editusergroup END ************************************************/


	/************************************** adduser BEGIN ************************************************/
	case "adduser":
echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div id="t1">
		<form id="userform" onsubmit="return false;">
		<div class="div_clear" style="height:10px;"></div>
		<table class="table_1">
			<tr><td class="td_0">用户名:<span class="required">(*)</span></td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="" size="30" name="user[username]" id="user[username]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">密码:<span class="required">(*)</span></td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="" size="30" name="user[userpass]" id="user[userpass]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_0">Email:<span class="required">(*)</span></td><td class=""></td></tr>
			<tr><td class="td_1"><input type="text" value="" size="30" name="user[email]" id="user[email]" class="text_css" /></td><td class="td_2"></td></tr>
			<tr><td class="td_3"><input class="button_css" type="button" value="  提  交  " onclick="ajax_adduser()" /></td><td class=""></td></tr>
		</table>
		</form>
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
	<script>
	var smallNowTab;
	var pt = new Tabs();
	pt.classpre="smalltab_";
	pt.container = "smalltab_container";
	pt.createTab("t1","添加用户","",true,"n");
	pt.init = function(){
		smallNowTab = pt.nowTab;
	};
	pt.onclick = function(){
		smallNowTab = pt.nowTab;
	};		
	pt.initTab();
	pt.clickNowTab();
	
	function ajax_adduser(){
		if(getV("user[username]")==""||getV("user[userpass]")==""||getV("user[email]")==""){
			var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
			popwin.showDialog(2,"提示","请填写完整必填项<span class='required'>(*)</span>",btns,280,130);
			return;
		}
		popwin.loading();
		ajaxPost("userform","user_ajax.php?action=adduser",ajax_adduser_callback);
	}
	function ajax_adduser_callback(data){
		popwin.loaded();
		if(data=="y"){
			var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
			popwin.showDialog(1,"修改成功","用户 ("+getV("user[username]")+")添加成功",btns,280,130);
		}else{
			var btns=[{value:" 确 定 ",onclick:"popwin.close();",focus:true}];
			popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
		}
	}
	
	</script>
EOT;
	break;
	/************************************** adduser END ************************************************/


	/************************************** manager/search BEGIN ************************************************/
	case "manager":
	case "search":
	require_once('../inc/pager.php');

echo <<<EOT
	<div id="smalltab_container"></div>
	<div class="smalltab_line"></div>
	<div id="t1">
EOT;
	if($action=="manager"){
echo <<<EOT
	<form onsubmit="return false;">
	<div class="div_clear" style="height:10px;"></div>
	<div class="tips_1"><b>提示</b><br />
	* 请先根据条件搜索用户，然后选择相应的操作。<br />
	</div>
	<div class="div_clear" style="height:10px;"></div>
	<table class="table_1">
		<tr><td class="td_0">用户UID:</td><td class=""></td></tr>
		<tr><td class="td_1"><input type="text" size="30" value="" name="userid" id="userid" class="text_css" /></td><td class="td_2"></td></tr>
		<tr><td class="td_0">用户名:</td><td class=""></td></tr>
		<tr><td class="td_1"><input type="text" size="30" value="" name="username" id="username" class="text_css" /></td><td class="td_2">可使用通配符 *</td></tr>
		<tr><td class="td_0">用户组:</td><td class=""></td></tr>
		<tr><td class="td_1"><select size="10" multiple="multiple" style='width:200px;padding-left:5px;' name="groupid" id="groupid"><option value="0">所有分组</option><optgroup label="普通组">{$cache_groups1option}</optgroup><optgroup label="系统组">{$cache_groups2option}</optgroup></select></td><td class="td_2">设置允许参与搜索的用户组，可以按住 CTRL 多选</td></tr>
		<tr><td class="td_3"><input class="button_css" type="button" value="  搜 索  " onclick="searchuser()" /></td><td class=""></td></tr>
	</table>
	</form>
EOT;
	 }else{
	 	$dwidth=array(0,35,190,160,70,100,100,200,140);
		$username=$_GET['username'];
		$username=str_replace("*","%",$username);
		if($username==""){$username="%";}
		$userid=numFilter($_GET['userid']);
		$groupid=$_GET['groupid'];
		$cond="username like '{$username}'";
		$cond.=($userid>0?" and id={$userid}":"");
		$cond.=(empty($groupid)||substr($groupid,0,2)=='0,' ?"":" and groupid in ({$groupid})");
		
		$curPage = numFilter($_GET["page"]);
		$pager = new Pager();
		$pager->init(10,$curPage,"admin.php?inc=user&action=search&username={$username}&userid={$userid}&groupid={$groupid}&page={page}");
		$rows = $pager->queryRows($db,"users", $cond , "*","id desc");
		
echo <<<EOT
	<div class="div_clear" style="height:10px;"></div>
	<div class="tips_1">共搜索到<b>{$pager->recordNum}</b>名符合条件的会员。<a href="admin.php?inc=user&action=manager">»返回重新搜索</a><br /></div>
EOT;
	echo("<form id=\"usersform\" onsubmit=\"return false;\">");
	echo("<table class=\"table_1\" width=\"100%\">");
	echo("<tr style=\"font-weight:bold;color:#333333;\"><td class=\"row_0\"><div class=\"rowdiv_0\" style=\"width:{$dwidth[1]}px;\"><span class=\"warning\">删除</span></div><div class=\"rowdiv_0\" style=\"width:{$dwidth[2]}px;\">用户名/邮箱</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[3]}px;\">注册时间/最后登录</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[8]}px;\">注册IP</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[4]}px;\">发帖数</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[5]}px;\">用户组</div><div class=\"rowdiv_0\" style=\"width:{$dwidth[7]}px;\">操作</div></td></tr>");
	for($i=0;$i<count($rows);$i++){
		$row=$rows[$i];
		$row['signuptime']=getDateStr($row['signuptime']);
		$row['logintime']=empty($row['logintime'])?'--':getDateStr($row['logintime']);
		$row['username']=htmlFilter($row['username']);
		$groupnamestr='';
		$checkboxstr='';
		if($row['groupid']>200){
			$groupnamestr="<span style='color:#FF6600;'>".$cache_groups[$row['groupid']]['groupname']."</span>";
			$checkboxstr="<input type=\"checkbox\" disabled=\"true\" class=\"checkbox_css\" />";
		}else{
			$groupnamestr="<span style='color:#333333;'>".$cache_groups[$row['groupid']]['groupname']."</span>";
			$checkboxstr="<input type=\"checkbox\" value=\"{$row['id']}\" name=\"deluid[]\" class=\"checkbox_css\" />";
		}
		echo("<tr><td class=\"row_0\" style=\"line-height:150%;\"><div class='rowdiv_0' style='width:{$dwidth[1]}px;'>{$checkboxstr}</div><div class='rowdiv_0' style='width:{$dwidth[2]}px;'><a href=\"../user.php?uid={$row['id']}\" target=\"_blank\">{$row['username']}</a><br />{$row['email']}</div><div class='rowdiv_0' style='width:{$dwidth[3]}px; font-size:11px;'>{$row['signuptime']}<br />{$row['logintime']}</div><div class='rowdiv_0' style='width:{$dwidth[8]}px;'><a href='".str_replace('{ip}',$row['signupip'], $cache_settings['iplink'])."' target='_blank'>{$row['signupip']}</a>&nbsp;</div><div class='rowdiv_0' style='width:{$dwidth[4]}px;'>{$row['postsnum']}</div><div class='rowdiv_0' style='width:{$dwidth[5]}px;'>{$groupnamestr}</div><div class='rowdiv_0' style='width:{$dwidth[7]}px;'><a href=\"admin.php?inc=user&action=edituser&uid={$row['id']}\">编辑</a> | <a href=\"admin.php?inc=user&action=editusergroup&uid={$row['id']}\">用户组</a></div></td></tr>");				
	}
	echo("</table>");
	echo("</form>");
	echo("<table width=100%><tr><td><input type=\"checkbox\" onclick=\"selectall(this.checked)\" class=\"checkbox_css\" /> 全选 &nbsp;  &nbsp; <input class=\"button_css\" type=\"button\" value=\"  删除所选  \" onclick=\"ajax_delusers_yn()\" /></td><td><div class='pagestrdiv'>{$pager->getPageStr()}</div></td></tr></table>");

 	}
echo <<<EOT
	
	</div>
	<div id="t2"></div>
	<div id="t3"></div>
	<div class="div_clear" style="height:30px;"></div>
<script>
var smallNowTab;
var pt = new Tabs();
pt.classpre="smalltab_";
pt.container = "smalltab_container";
pt.createTab("t1","用户管理","",true,"n");
//pt.createTab("t2","批量删除","",false,"n");
pt.init = function(){
	smallNowTab = pt.nowTab;
};
pt.onclick = function(){
	smallNowTab = pt.nowTab;
};		
pt.initTab();
pt.clickNowTab();

function selectall(b){
	var oForm=getE("usersform");
	for (var i = 0; i < oForm.elements.length; i++) {
		if(oForm.elements[i].type=="checkbox"&&!oForm.elements[i].disabled){
			oForm.elements[i].checked = b;
		}
	}
}

function searchuser(){
	var loc = "admin.php?inc=user&action=search&username="+document.getElementById("username").value+"&userid="+document.getElementById("userid").value+"&groupid="+getMultipleValue(document.getElementById("groupid"));
	self.location.href = loc;
}

function ajax_delusers_yn(){
	var btns=[
		{value:" 确 认 ",onclick:"mainifm.ajax_delusers()",focus:true},
		{value:" 取 消 ",onclick:"popwin.close()"}
	];
	popwin.showDialog(3,"确认","该操作会删除该用户的帐号与帖子，并不可恢复。<br />是否确认删除？",btns,320,130);
}

function ajax_delusers(){
	popwin.loading();
	ajaxPost("usersform","user_ajax.php?action=delusers",ajax_delusers_callback);
}
function ajax_delusers_callback(data){
	var btns=[{value:" 确 定 ",onclick:"popwin.close();mainifm.location.reload();",focus:true}];
	popwin.loaded();
	if(data=="y"){
		popwin.showDialog(1,"删除成功","用户删除成功",btns,280,130);
	}else{
		popwin.showDialog(0,"操作失败","操作失败:<br />"+data,btns,280,130);
	}
}

function PageInit(){
	if(E("username")){E("username").onkeyup = function(event){checkKeyPressEnter(event);};E("username").focus();}
	if(E("userid")){E("userid").onkeyup = function(event){checkKeyPressEnter(event);};}
	
}

function checkKeyPressEnter(eventobject){
	var eve=eventobject||window.event;
	if(eve.keyCode==13) {
		searchuser();
	}
}
window.onload=PageInit;

</script>
EOT;
	break;
	/**************************************  manager/search END ************************************************/
}	
?>